package com.csw.util;

import com.csw.pojo.Brand;

import java.util.Random;

/**
 * @author A
 * @version 1.0
 * @description: TODO
 * @date 2022/11/30 2:48
 */
public class BrandUtil {
    static Random random = new Random();
    //返回装满牌名的数组
    public static String[] getNames(){
        return new String[]{"刷子","剪刀","叉子","手套","水桶","火","玉米","球","瓶子","白菜","稻草","肉腿","胡萝卜","苹果"
                ,"铃铛","青草"
        };
    }
    //每次调用拿取随机name
    public static String getRandomName(){

        String[] names = getNames();
        int i = random.nextInt(names.length);
        return names[i];

    }
    //返回随机的打乱顺序的,长度为Layer容量且为3的倍数的Brand数组
    public static Brand[] bulidBrands(int capacity){
        Brand[] brands = new Brand[capacity];
        //生成3的倍数
        for (int i = 0; i <capacity ; i+=3) {
            String randomName = getRandomName();
            Brand brand1 = new Brand(randomName);
            Brand brand2 = new Brand(randomName);
            Brand brand3 = new Brand(randomName);
            brands[i]=brand1;
            brands[i+1]=brand2;
            brands[i+2]=brand3;
        }
//        for (int i = 0; i < brands.length; i++) {
//            System.out.print(brands[i].getName()+"_");
//        }
        //随机互换位置
        for (int i = 0; i < brands.length; i++) {
            Brand brandA = brands[i];
            Brand temp = brandA;
            int i1 = random.nextInt(brands.length);
            Brand brandB = brands[i1];
            brands[i]=brandB;
            brands[i1]=temp;
        }
//        System.out.println("");
//        for (int i = 0; i < brands.length; i++) {
//
//            System.out.print(brands[i].getName()+"_");
//        }
        return brands;
    }


}
